clear 
set more off

/*NOTE: PSID_retrospective_analysis.dta is created in the 
        build/PSID folder. */

    use "$PSID/output/PSID_retrospective_analysis.dta", clear
    keep if firstobs_son==1
    tab year
    local weight "xsection_weight" 

    foreach yy in 70 {
    
    * Ranks
        corr rank_father_retro_mode_`yy' rank_father_5yrs_`yy' [aw=`weight']
        local corr1 = `r(rho)'
        local number: display %04.2fc `corr1'   

        #delimit ;
            binscatter rank_father_retro_mode_`yy' rank_father_5yrs_`yy' [aw=`weight'], 
            nquantiles(20) msymbol(circle) mcolors( navy) lcolors( navy) scheme(s1color) ttext(80 20 "Correlation: `number'")
            xti(" " "Ranked predicted income, self-reported") yti("Ranked predicted income, retrospective" " ") legend(off) yscale(range(0 100)) ylabel(0(20)100);
        #delimit cr
        graph export "$Mydirectory2/appendix_c/Scatter_rank_retro_vs_5yrs_score`yy'.pdf", as(pdf) replace
    
    * Logs
        corr log_father_retro_mode_`yy' log_father_5yrs_`yy' [aw=`weight']
        local corr1 = `r(rho)'
        local number: display %04.2fc `corr1'   
        
        if "`yy'"=="70" {
            local numb "9.25 8.5"
            local cond1 "scale(range(8 9.5))"
            local cond2 "label(8(0.5)9.5)"
        }

        #delimit ;
            binscatter log_father_retro_mode_`yy' log_father_5yrs_`yy' [aw=`weight'], 
            nquantiles(20) msymbol(circle) mcolors( navy) lcolors( navy) scheme(s1color) ttext(`numb' "Correlation: `number'") x`cond1' x`cond2'
            xti(" " "Logged predicted income, self-reported") yti("Logged predicted income, retrospective" " ") legend(off) y`cond1' y`cond2' ;
        #delimit cr
        graph export "$Mydirectory2/appendix_c/Scatter_log_retro_vs_5yrs_score`yy'.pdf", as(pdf) replace
    }
